package at.ac.univie.zsu.aguataplan.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

/**
 * @author gerry
 * 
 */
@Entity
public class Ranking {

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	@Column
	private Long id;

	@Version
	@Column
	private Integer version;

	@NotNull
	@Column
	private String description;

	@NotNull
	@Column
	private int ranking;

	@OneToMany(cascade = CascadeType.ALL)
	private Set<WorkingDescription> refWorkingDescription = new HashSet<WorkingDescription>();

	// ----------------------------------------------------
	// CONSTRUCTOR
	// ----------------------------------------------------

	public Ranking() {

	}

	// ----------------------------------------------------
	// METHODS
	// ----------------------------------------------------

	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Description: ").append(getDescription()).append(", ");
		sb.append("Id: ").append(getId()).append(", ");
		sb.append("Ranking: ").append(getRanking()).append(", ");
		sb.append("RefWorkingDescription: ")
				.append(getRefWorkingDescription() == null ? "null"
						: getRefWorkingDescription().size()).append(", ");
		sb.append("Version: ").append(getVersion());
		return sb.toString();
	}

	// ----------------------------------------------------
	// GETTER & SETTER
	// ----------------------------------------------------

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getRanking() {
		return ranking;
	}

	public void setRanking(int ranking) {
		this.ranking = ranking;
	}

	public Set<WorkingDescription> getRefWorkingDescription() {
		return refWorkingDescription;
	}

	public void setRefWorkingDescription(
			Set<WorkingDescription> refWorkingDescription) {
		this.refWorkingDescription = refWorkingDescription;
	}

}
